home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -in_the_mag- / reader_requests / xgtool / xgtoolset / source / xgmain / xgmain.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  57KB  |  1,959 lines

  1. /*
  2.     MNXG-Editor V1.6
  3.  
  4.     A Bars and Pipes tool for editing the DB50-XG-board from  YAMAHA.  It's
  5.     also  useable   for  other  GM-equipment.  But  then  don't  touch  the
  6.     Bank-slider.
  7.  
  8.     Use it together with the other XG ... .ptool ' s -
  9.  
  10.     © 1998 Alfred & Matthias Faust
  11.  
  12.     The Tool-code based farly on the code for the "pc3.ptool" from  Richard
  13.     Hagen. That's a very good tool,  many thanks to him.
  14.  
  15.     Richard has written his tool with DICE. We altered the code to  compile
  16.     with  the  free  GNU-C-compiler  of  the  ADE.  Especially the part was
  17.     transcripted,   that  place  the  imagedate  in  chip-RAM,   because  the
  18.     GNU-C-compiler  hasn't as yet a keyword like DICE or other compiler for
  19.     this.
  20.  
  21.     This code is released  into  the  Public  Domain,   and  may  be  freely
  22.     distributed in its original form.
  23.  
  24.     It is supplied ``as is'',  and comes with no warranty. This program code
  25.     was  released  because it might be useful as a starting point for other
  26.     programmers. However,  if any damage arises from its use,   the  original
  27.     author and we will not be held liable.
  28.  
  29.     You are free to use and modify  this  code  to  your  heart's  content,
  30.     provided you acknowledge me as the original author in any code that you
  31.     might distribute which is based largely on this code.
  32.  
  33.     I acknowledge that the design of this tool is  influenced  strongly  by
  34.     the  example code supplied with the Rules for Tools package. However,  I
  35.     have made substantial contributions of my own.
  36.  
  37.     Matthias & Alfred Faust
  38.     j.k.dax@t-online.de
  39.  
  40.     History:
  41.     1.0 (17.11.1998)
  42.     Initial Release.
  43.     Transcription from DB50XG.ptool
  44.  
  45.  
  46.     
  47. */
  48.  
  49. #include "bars.h"
  50. #include "myheader.h"  // from R.Hagen
  51. #include <libraries/dos.h>
  52. #include <proto/exec.h>
  53. #include <proto/intuition.h>
  54. #include <proto/graphics.h>
  55. #include <exec/memory.h>
  56. #include <exec/execbase.h>
  57. #include <exec/types.h>
  58. #include <string.h>
  59. #include <intuition/intuition.h>
  60.  
  61. #include "hexstrings.c"   //translation hexbytes->hexstrings
  62. #include "soundmatrix.c"  //all the soundnames
  63.  
  64. char version[]="\0$VER:MNXG-Edit 1.0 (17.11.98) © Alfred & Matthias Faust";
  65.  
  66. #define MNXG_NAME "XG-Main-Edit"
  67.  
  68. #define MNXG_ID          0x344E5847
  69. #define MNXG_TYPE        (TOOL_NORMAL | TOOL_NOTPAD)
  70.  
  71. //Definitions of the controllers
  72.  
  73. #define CTR1  1   //Modulation
  74. #define CTR7  7   //Main Volume
  75. #define CTR10 10  //Panpot
  76. #define CTR11 11  //Expression
  77. #define CTR32 32  //Bank select in XG-Mode
  78. #define CTR71 71  //Harmonic Content
  79. #define CTR72 72  //Release Time
  80. #define CTR73 73  //Attack Time
  81. #define CTR74 74  //Brightness
  82. #define CTR91 91  //Reverb Send Level
  83. #define CTR93 93  //Chorus Send Level
  84. #define CTR94 94  //Variation Send Level
  85.  
  86. // Hall-Effects  300 ->
  87.  
  88. #define hall1      0
  89. #define hall2      1
  90. #define room1      2
  91. #define room2      3
  92. #define room3      4
  93. #define stage1     5
  94. #define stage2     6
  95. #define plate      7
  96. #define whiteroom  8
  97. #define tunnel     9
  98. #define basement   10
  99.  
  100.  
  101. /* the litte Icon in the pipeline */
  102.  
  103. UWORD *MNXG=NULL;
  104.  
  105. static UWORD MNXGdata[] =
  106. {
  107.  /* Plane 0 */
  108.      0x7FFF, 0xFE00,
  109.      0x7FFF, 0xFE00,
  110.      0x6000, 0xF600,
  111.      0x6FEE, 0xE600,
  112.      0x6FDE, 0x0600,
  113.      0x6EF0, 0x0600,
  114.      0x6FDE, 0x0600,
  115.      0x6FBE, 0x0600,
  116.      0x6AB4, 0xE600,
  117.      0x6000, 0xF600,
  118.      0x7FFF, 0xFE00,
  119.      0x7FFF, 0xFE00,
  120.  /* Plane 1 */
  121.      0x0000, 0x0200,
  122.      0x0000, 0x0600,
  123.      0x0000, 0xF600,
  124.      0x0FFE, 0xEE00,
  125.      0x89FE, 0x1F00,
  126.      0x8EFE, 0x1F00,
  127.      0x89FE, 0x1F00,
  128.      0x8FBE, 0x1F00,
  129.      0x0AB6, 0xEE00,
  130.      0x0000, 0xF600,
  131.      0x1FFF, 0xFE00,
  132.      0x3FFF, 0xFE00,
  133.  /* Plane 2 */
  134.      0x0000, 0x0000,
  135.      0x0000, 0x0000,
  136.      0x0000, 0xF000,
  137.      0x0FFE, 0xE800,
  138.      0x0FFE, 0x1800,
  139.      0x0EF0, 0x7800,
  140.      0x0FDE, 0x7800,
  141.      0x0FFE, 0x1800,
  142.      0x0AF4, 0xE800,
  143.      0x0000, 0xF000,
  144.      0x0000, 0x0000,
  145.      0x0000, 0x0000
  146.  
  147. };
  148.  
  149. static struct Image MNXG_image = {
  150.   0, 0,
  151.   24 ,  12 ,  3 ,
  152.   NULL,
  153.   0x1f, 0x00,
  154.   NULL
  155. };
  156.  
  157.  
  158. //Definitions of the gadgets
  159.  
  160. #define VOLUME_GADGET 1
  161. #define VOLUMEDOWN_GADGET 2
  162. #define VOLUMEUP_GADGET 3
  163.  
  164. #define PANPOT_GADGET 4
  165. #define PANPOTDOWN_GADGET 5
  166. #define PANPOTUP_GADGET 6
  167.  
  168. #define REVERB_GADGET 7
  169. #define REVERBDOWN_GADGET 8
  170. #define REVERBUP_GADGET 9
  171.  
  172. #define CHORUS_GADGET 10
  173. #define CHORUSDOWN_GADGET 11
  174. #define CHORUSUP_GADGET 12
  175.  
  176. #define VARIATION_GADGET 13
  177. #define VARIATIONDOWN_GADGET 14
  178. #define VARIATIONUP_GADGET 15
  179.  
  180. #define HARMONIC_GADGET 16
  181. #define HARMONICDOWN_GADGET 17
  182. #define HARMONICUP_GADGET 18
  183.  
  184. #define BRIGHT_GADGET 19
  185. #define BRIGHTDOWN_GADGET 20
  186. #define BRIGHTUP_GADGET 21
  187.  
  188. #define VIBRATO_GADGET 22
  189. #define VIBRATODOWN_GADGET 23
  190. #define VIBRATOUP_GADGET 24
  191.  
  192. #define EXPRESSION_GADGET 25
  193. #define EXPRESSIONDOWN_GADGET 26
  194. #define EXPRESSIONUP_GADGET 27
  195.  
  196. #define ATTACK_GADGET 28
  197. #define ATTACKDOWN_GADGET 29
  198. #define ATTACKUP_GADGET 30
  199.  
  200. #define RELEASE_GADGET 31
  201. #define RELEASEDOWN_GADGET 32
  202. #define RELEASEUP_GADGET 33
  203.  
  204. #define BANK_GADGET 34
  205. #define BANKDOWN_GADGET 35
  206. #define BANKUP_GADGET 36
  207.  
  208. #define PC_GADGET 37
  209. #define PCDOWN_GADGET 38
  210. #define PCUP_GADGET 39
  211.  
  212. #define WRITE_GADGET 40
  213.  
  214. #define TEST_GADGET 41
  215.  
  216. #define P01_GADGET 42
  217.  
  218. #define DEFAULT_GADGET 43
  219.  
  220. #define INSY_GADGET 45
  221.  
  222. //all the gadgets
  223.  
  224. /* VOLUME gadget. */
  225. struct PropInfo MNXGMNXGGadget1SInfo = {
  226.   AUTOKNOB|FREEHORIZ, -16384,  -1, 16384,  -1,
  227. };
  228.  
  229. struct Image MNXGImage1 = {
  230.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  231. };
  232.  
  233. struct IntuiText MNXGIText1 = {
  234.   2, 0, JAM1, -70, 1, NULL, "  Volume", NULL
  235. };
  236.  
  237. struct Gadget MNXGGadget1 = {
  238.   NULL, 89, 16, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  239.   (APTR)&MNXGImage1, NULL, &MNXGIText1, NULL, (APTR)&MNXGMNXGGadget1SInfo, VOLUME_GADGET, NULL
  240. };
  241.  
  242. /* Panpot gadget. */
  243. struct PropInfo MNXGMNXGGadget2SInfo = {
  244.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  245. };
  246.  
  247. struct Image MNXGImage2 = {
  248.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  249. };
  250.  
  251. struct IntuiText MNXGIText2 = {
  252.   2, 0, JAM1, -70, 1, NULL, "  Panpot", NULL
  253. };
  254.  
  255. struct Gadget MNXGGadget2 = {
  256.   &MNXGGadget1, 89, 28, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  257.   (APTR)&MNXGImage2, NULL, &MNXGIText2, NULL, (APTR)&MNXGMNXGGadget2SInfo, PANPOT_GADGET, NULL
  258. };
  259.  
  260. /* REVERB gadget. */
  261. struct PropInfo MNXGMNXGGadget3SInfo = {
  262.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  263. };
  264.  
  265. struct Image MNXGImage3 = {
  266.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  267. };
  268.  
  269. struct IntuiText MNXGIText3 = {
  270.   2, 0, JAM1, -70, 1, NULL, "  Reverb", NULL
  271. };
  272.  
  273. struct Gadget MNXGGadget3 = {
  274.   &MNXGGadget2, 89, 40, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  275.   (APTR)&MNXGImage3, NULL, &MNXGIText3, NULL, (APTR)&MNXGMNXGGadget3SInfo, REVERB_GADGET, NULL
  276. };
  277.  
  278. /* Chorus gadget. */
  279. struct PropInfo MNXGMNXGGadget4SInfo = {
  280.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  281. };
  282.  
  283. struct Image MNXGImage4 = {
  284.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  285. };
  286.  
  287. struct IntuiText MNXGIText4 = {
  288.   2, 0, JAM1, -70,  1, NULL, "  Chorus", NULL
  289. };
  290.  
  291. struct Gadget MNXGGadget4 = {
  292.   &MNXGGadget3, 89, 52, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  293.   (APTR)&MNXGImage4, NULL, &MNXGIText4, NULL, (APTR)&MNXGMNXGGadget4SInfo, CHORUS_GADGET, NULL
  294. };
  295.  
  296. // Variations gadget.
  297.  
  298. struct PropInfo MNXGMNXGGadget5SInfo = {
  299.   AUTOKNOB+FREEHORIZ,  -16384,  -1,  16384,  -1,
  300. };
  301.  
  302. struct Image MNXGImage5 = {
  303.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  304. };
  305.  
  306. struct IntuiText MNXGIText5 = {
  307.   2, 0, JAM1, -70,  1,  NULL,  "  Var-FX",  NULL
  308. };
  309.  
  310. struct Gadget MNXGGadget5 = {
  311.   &MNXGGadget4, 89, 64, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  312.   (APTR)&MNXGImage5, NULL, &MNXGIText5, NULL, (APTR)&MNXGMNXGGadget5SInfo, VARIATION_GADGET, NULL
  313. };
  314.  
  315.  
  316. /* HARMONIC gadget. */
  317. struct PropInfo MNXGMNXGGadget6SInfo = {
  318.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  319. };
  320.  
  321. struct Image MNXGImage6 = {
  322.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  323. };
  324.  
  325. struct IntuiText MNXGIText6 = {
  326.   2, 0, JAM1, -70, 1, NULL, "Harmonic", NULL
  327. };
  328.  
  329. struct Gadget MNXGGadget6 = {
  330.   &MNXGGadget5, 89, 76, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  331.   (APTR)&MNXGImage6, NULL, &MNXGIText6, NULL, (APTR)&MNXGMNXGGadget6SInfo, HARMONIC_GADGET, NULL
  332. };
  333.  
  334. /* BRIGHT */
  335. struct PropInfo MNXGMNXGGadget7SInfo = {
  336.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  337. };
  338.  
  339. struct Image MNXGImage7 = {
  340.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  341. };
  342.  
  343. struct IntuiText MNXGIText7 = {
  344.   2, 0, JAM1, -70, 1, NULL, "  Bright", NULL
  345. };
  346.  
  347. struct Gadget MNXGGadget7 = {
  348.   &MNXGGadget6, 89, 88, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  349.   (APTR)&MNXGImage7, NULL, &MNXGIText7, NULL, (APTR)&MNXGMNXGGadget7SInfo, BRIGHT_GADGET, NULL
  350. };
  351.  
  352. /* Vibrato */
  353. struct PropInfo MNXGMNXGGadget8SInfo = {
  354.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  355. };
  356.  
  357. struct Image MNXGImage8 = {
  358.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  359. };
  360.  
  361. struct IntuiText MNXGIText8 = {
  362.   2, 0, JAM1, -70, 1, NULL, " Vibrato", NULL
  363. };
  364.  
  365. struct Gadget MNXGGadget8 = {
  366.   &MNXGGadget7, 89, 100, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  367.   (APTR)&MNXGImage8, NULL, &MNXGIText8, NULL, (APTR)&MNXGMNXGGadget8SInfo, VIBRATO_GADGET, NULL
  368. };
  369.  
  370. /* EXPRESSION */
  371. struct PropInfo MNXGMNXGGadget9SInfo = {
  372.   AUTOKNOB|FREEHORIZ, -16384,  -1, 16384,  -1,
  373. };
  374.  
  375. struct Image MNXGImage9 = {
  376.   00, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  377. };
  378.  
  379. struct IntuiText MNXGIText9 = {
  380.   2, 0, JAM1, -70, 1, NULL, "Express.",  NULL
  381. };
  382.  
  383. struct Gadget MNXGGadget9 = {
  384.   &MNXGGadget8, 89, 112, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  385.   (APTR)&MNXGImage9, NULL, &MNXGIText9, NULL, (APTR)&MNXGMNXGGadget9SInfo, EXPRESSION_GADGET, NULL
  386. };
  387.  
  388. /* ATTACK */
  389. struct PropInfo MNXGMNXGGadget10SInfo = {
  390.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  391. };
  392.  
  393. struct Image MNXGImage10 = {
  394.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  395. };
  396.  
  397. struct IntuiText MNXGIText10 = {
  398.   2, 0, JAM1, -70, 1, NULL, "  Attack", NULL
  399. };
  400.  
  401. struct Gadget MNXGGadget10 = {
  402.   &MNXGGadget9, 89, 124, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  403.   (APTR)&MNXGImage10, NULL, &MNXGIText10, NULL, (APTR)&MNXGMNXGGadget10SInfo, ATTACK_GADGET, NULL
  404. };
  405.  
  406. /* RELEASE */
  407. struct PropInfo MNXGMNXGGadget11SInfo = {
  408.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  409. };
  410.  
  411. struct Image MNXGImage11 = {
  412.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  413. };
  414.  
  415. struct IntuiText MNXGIText11 = {
  416.   2, 0, JAM1, -70, 1, NULL, " Release", NULL
  417. };
  418.  
  419. struct Gadget MNXGGadget11 = {
  420.   &MNXGGadget10, 89, 136, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  421.   (APTR)&MNXGImage11, NULL, &MNXGIText11, NULL, (APTR)&MNXGMNXGGadget11SInfo, RELEASE_GADGET, NULL
  422. };
  423.  
  424.  
  425. /* BANK gadget. */
  426. struct PropInfo MNXGMNXGGadget12SInfo = {
  427.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  428. };
  429.  
  430. struct Image MNXGImage12 = {
  431.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  432. };
  433.  
  434. struct IntuiText MNXGIText12 = {
  435.   2, 0, JAM1, -70,  1, NULL, "    Bank", NULL
  436. };
  437.  
  438. struct Gadget MNXGGadget12 = {
  439.   &MNXGGadget11, 89, 163, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  440.   (APTR)&MNXGImage12, NULL, &MNXGIText12, NULL, (APTR)&MNXGMNXGGadget12SInfo, BANK_GADGET, NULL
  441. };
  442.  
  443. /* PC gadget. */
  444. struct PropInfo MNXGMNXGGadget13SInfo = {
  445.   AUTOKNOB+FREEHORIZ, -16384,  -1, 16384,  -1,
  446. };
  447.  
  448. struct Image MNXGImage13 = {
  449.   0, 0, 102, 6, 0, NULL, 0x0000, 0x0000, NULL
  450. };
  451.  
  452. struct IntuiText MNXGIText13 = {
  453.   2, 0, JAM1, -70, 1, NULL, "   Prgm#", NULL
  454. };
  455.  
  456. struct Gadget MNXGGadget13 = {
  457.   &MNXGGadget12, 89, 175, 200, 10, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, PROPGADGET,
  458.   (APTR)&MNXGImage13, NULL, &MNXGIText13, NULL, (APTR)&MNXGMNXGGadget13SInfo, PC_GADGET, NULL
  459. };
  460.  
  461. /* Write to track gadget. */
  462.  
  463. struct IntuiText MNXGIText14 = {
  464.   4, 0, JAM1, 4, 2, NULL, "Write to Track", NULL
  465.   };
  466.  
  467. struct Gadget MNXGGadget14 = {
  468.   &MNXGGadget13, 11, 195, 118, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
  469.   NULL, NULL, &MNXGIText14, NULL, NULL, WRITE_GADGET, NULL
  470.   };
  471.  
  472. /* Test gadget. */
  473.  
  474. struct IntuiText MNXGIText15 = {
  475.   4, 0, JAM1, 4, 2, NULL, "Test", NULL
  476.   };
  477.  
  478. struct Gadget MNXGGadget15 = {
  479.   &MNXGGadget14, 279, 195, 40, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
  480.   NULL, NULL, &MNXGIText15, NULL, NULL, TEST_GADGET, NULL
  481.   };
  482.  
  483. /* P01 gadget. */
  484.  
  485. struct IntuiText MNXGIText16 = {
  486.   4, 0, JAM1, 2, 2, NULL, "", NULL
  487.   };
  488.  
  489. struct Gadget MNXGGadget16 = {
  490.   &MNXGGadget15, 25, 175, 11, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
  491.   NULL, NULL, &MNXGIText16, NULL, NULL, P01_GADGET, NULL
  492.   };
  493.  
  494. /* DEFAULT gadget. */
  495.  
  496. struct IntuiText MNXGIText17 = {
  497.   4, 0, JAM1, 4, 2, NULL, "Default", NULL
  498.   };
  499.  
  500. struct Gadget MNXGGadget17 = {
  501.   &MNXGGadget16, 173, 195, 65, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
  502.   NULL, NULL, &MNXGIText17, NULL, NULL, DEFAULT_GADGET, NULL
  503.   };
  504.  
  505.  
  506. UBYTE insy[] = {"I"};
  507.  
  508. /* VariationFX : Insertion<>System  */
  509.  
  510. struct IntuiText MNXGIText18 = {
  511.   4, 0, JAM1, 1, 2, NULL, insy, NULL
  512.   };
  513.  
  514. struct Gadget MNXGGadget18 = {
  515.   &MNXGGadget17, 16, 63, 11, 11, GADGHBOX+GADGHIMAGE, GADGIMMEDIATE|TOGGLESELECT, BOOLGADGET,
  516.   NULL, NULL, &MNXGIText18, NULL, NULL, INSY_GADGET, NULL
  517.   };
  518.  
  519.  
  520. //the mainwindowstructure
  521.  
  522. struct NewWindow MNXGNewWindowStructure1 = {
  523.   5, 15,
  524.   331,  215,
  525.   0, 6,
  526.   GADGETDOWN|GADGETUP|CLOSEWINDOW,
  527.   WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|ACTIVATE|NOCAREREFRESH,
  528.   &MNXGGadget18,
  529.   NULL,
  530.   "XG Main Editor",
  531.   NULL,
  532.   NULL,
  533.   5, 5,
  534.   -1, -1,
  535.   CUSTOMSCREEN
  536. };
  537.  
  538. extern struct ExecBase * SysBase;
  539. UBYTE p,  prgrm,  banknr,  ins=0;
  540.  
  541.  
  542.  
  543. struct MNXGTool {
  544.   struct Tool tool;
  545.  
  546.   UBYTE volume;
  547.   UBYTE panpot;
  548.   UBYTE reverb;
  549.   UBYTE chorus;
  550.   UBYTE variation;
  551.   UBYTE harmonic;
  552.   UBYTE bright;
  553.   UBYTE vibrato;
  554.   UBYTE expression;
  555.   UBYTE attack;
  556.   UBYTE release;
  557.   UBYTE bank;
  558.   UBYTE pc;
  559.  
  560.   char *insysysex;
  561.   char *resetsysex;
  562.   char *xgonsysex;
  563. };
  564.  
  565. static struct ToolMaster master;
  566.  
  567. extern struct Functions *functions;
  568.  
  569. //initial values
  570. static void MNXG_tool_init(struct MNXGTool *tool)
  571. {
  572.   tool->tool.touched = TOUCH_INIT;
  573.  
  574.   tool->volume          = 100;
  575.   tool->panpot          = 64;
  576.   tool->reverb          = 40;
  577.   tool->chorus          = 0;
  578.   tool->variation       = 40;
  579.   tool->harmonic        = 64;
  580.   tool->bright          = 64;
  581.   tool->vibrato         = 0;
  582.   tool->expression      = 127;
  583.   tool->attack          = 64;
  584.   tool->release         = 64;
  585.   tool->bank            = 0;
  586.   tool->pc              = 0;
  587.  
  588.   tool->insysysex  = NULL;
  589.   tool->resetsysex = "F07E7F0901F7";
  590.   tool->xgonsysex  = "F043104C00007E00F7";
  591. }
  592.  
  593.  
  594. static struct Event * __saveds processeventcode(struct Event *event)
  595. {
  596.   event->tool = event->tool->next;
  597.   return(event);
  598. }
  599.  
  600. static BOOL lock_clip(struct Clip *clip)
  601. {
  602.   Forbid();
  603.   if (clip->locked == 0)
  604.     {
  605.       clip->locked = 1;
  606.       Permit();
  607.       return TRUE;
  608.     }
  609.   else
  610.     {
  611.       Permit();
  612.       return FALSE;
  613.     }
  614. }
  615.  
  616. static void unlock_clip(struct Clip *clip)
  617. {
  618.   clip->locked = 0;
  619. }
  620.  
  621. static void send_pc(struct MNXGTool *tool,  const long time)
  622. {
  623.  struct Event *volume_event = (struct Event *)(*functions->allocevent)();
  624.  if (volume_event)
  625.  {
  626.   struct Event *panpot_event = (struct Event *)(*functions->allocevent)();
  627.   if (panpot_event)
  628.   {
  629.    struct Event *reverb_event = (struct Event *)(*functions->allocevent)();
  630.    if (reverb_event)
  631.    {
  632.     struct Event *chorus_event = (struct Event *)(*functions->allocevent)();
  633.     if (chorus_event)
  634.     {
  635.      struct Event *variation_event = (struct Event *)(*functions->allocevent)();
  636.      if (variation_event)
  637.      {
  638.       struct Event *harmonic_event = (struct Event *)(*functions->allocevent)();
  639.       if (harmonic_event)
  640.       {
  641.        struct Event *bright_event = (struct Event *)(*functions->allocevent)();
  642.        if (bright_event)
  643.        {
  644.     struct Event *vibrato_event = (struct Event *)(*functions->allocevent)();
  645.     if (vibrato_event)
  646.     {
  647.      struct Event *expression_event = (struct Event *)(*functions->allocevent)();
  648.      if (expression_event)
  649.      {
  650.       struct Event *attack_event = (struct Event *)(*functions->allocevent)();
  651.       if (attack_event)
  652.       {
  653.        struct Event *release_event = (struct Event *)(*functions->allocevent)();
  654.        if (release_event)
  655.        {
  656.         struct Event *bank_event = (struct Event *)(*functions->allocevent)();
  657.         if (bank_event)
  658.         {
  659.          struct Event *pc_event = (struct Event *)(*functions->allocevent)();
  660.          if (pc_event)
  661.          {
  662.           volume_event->type     =
  663.           panpot_event->type     =
  664.           reverb_event->type     =
  665.           chorus_event->type     =
  666.           variation_event->type  =
  667.           harmonic_event->type   =
  668.           bright_event->type     =
  669.           vibrato_event->type    =
  670.           expression_event->type =
  671.           attack_event->type     =
  672.           release_event->type    =
  673.           bank_event->type       =
  674.           pc_event->type         = EVENT_VOICE;
  675.  
  676.           volume_event->status = MIDI_CCHANGE;
  677.           volume_event->byte1 = CTR7;
  678.           volume_event->byte2 = tool->volume;
  679.  
  680.           panpot_event->status = MIDI_CCHANGE;
  681.           panpot_event->byte1 = CTR10;
  682.           panpot_event->byte2 = tool->panpot;
  683.  
  684.           reverb_event->status = MIDI_CCHANGE;
  685.           reverb_event->byte1 = CTR91;
  686.           reverb_event->byte2 = tool->reverb;
  687.  
  688.           chorus_event->status = MIDI_CCHANGE;
  689.           chorus_event->byte1 = CTR93;
  690.           chorus_event->byte2 = tool->chorus;
  691.  
  692.           variation_event->status = MIDI_CCHANGE;
  693.           variation_event->byte1 = CTR94;
  694.           variation_event->byte2 = tool->variation;
  695.  
  696.           harmonic_event->status = MIDI_CCHANGE;
  697.           harmonic_event->byte1 = CTR71;
  698.           harmonic_event->byte2 = tool->harmonic;
  699.  
  700.           bright_event->status = MIDI_CCHANGE;
  701.           bright_event->byte1 = CTR74;
  702.           bright_event->byte2 = tool->bright;
  703.  
  704.           vibrato_event->status = MIDI_CCHANGE;
  705.           vibrato_event->byte1 = CTR1;
  706.           vibrato_event->byte2 = tool->vibrato;
  707.  
  708.           expression_event->status = MIDI_CCHANGE;
  709.           expression_event->byte1 = CTR11;
  710.           expression_event->byte2 = tool->expression;
  711.  
  712.           attack_event->status = MIDI_CCHANGE;
  713.           attack_event->byte1 = CTR73;
  714.           attack_event->byte2 = tool->attack;
  715.  
  716.           release_event->status = MIDI_CCHANGE;
  717.           release_event->byte1 = CTR72;
  718.           release_event->byte2 = tool->release;
  719.  
  720.           bank_event->status = MIDI_CCHANGE;
  721.           bank_event->byte1 = CTR32;
  722.           bank_event->byte2 = banknr;
  723.  
  724.           pc_event->status = MIDI_PCHANGE;
  725.           pc_event->byte1 = tool->pc;
  726.  
  727.           volume_event->time     = time;
  728.           panpot_event->time     = time;
  729.           reverb_event->time     = time;
  730.           chorus_event->time     = time;
  731.           variation_event->time  = time;
  732.           harmonic_event->time   = time;
  733.           bright_event->time     = time;
  734.           vibrato_event->time    = time;
  735.           expression_event->time = time;
  736.           attack_event->time     = time;
  737.           release_event->time    = time;
  738.           bank_event->time       = time;
  739.           pc_event->time         = time+1;
  740.  
  741.           volume_event->tool     =
  742.           panpot_event->tool     =
  743.           reverb_event->tool     =
  744.           chorus_event->tool     =
  745.           variation_event->tool  =
  746.           harmonic_event->tool   =
  747.           bright_event->tool     =
  748.           vibrato_event->tool    =
  749.           expression_event->tool =
  750.           attack_event->tool     =
  751.           release_event->tool    =
  752.           bank_event->tool       =
  753.           pc_event->tool         = tool->tool.next;
  754.  
  755.  
  756.           volume_event->next     =
  757.           panpot_event->next     =
  758.           reverb_event->next     =
  759.           chorus_event->next     =
  760.           variation_event->next  =
  761.           harmonic_event->next   =
  762.           bright_event->next     =
  763.           vibrato_event->next    =
  764.           expression_event->next =
  765.           attack_event->next     =
  766.           release_event->next    =
  767.           bank_event->next       =
  768.           pc_event->next         = NULL;
  769.  
  770.           (*functions->qevent)(volume_event);
  771.           (*functions->qevent)(panpot_event);
  772.           (*functions->qevent)(reverb_event);
  773.           (*functions->qevent)(chorus_event);
  774.           (*functions->qevent)(variation_event);
  775.           (*functions->qevent)(harmonic_event);
  776.           (*functions->qevent)(bright_event);
  777.           (*functions->qevent)(vibrato_event);
  778.           (*functions->qevent)(expression_event);
  779.           (*functions->qevent)(attack_event);
  780.           (*functions->qevent)(release_event);
  781.           (*functions->qevent)(bank_event);
  782.           (*functions->qevent)(pc_event);
  783.          }
  784.          else
  785.          {
  786.          (*functions->freeevent)(volume_event);
  787.          (*functions->freeevent)(panpot_event);
  788.          (*functions->freeevent)(reverb_event);
  789.          (*functions->freeevent)(chorus_event);
  790.          (*functions->freeevent)(variation_event);
  791.          (*functions->freeevent)(harmonic_event);
  792.          (*functions->freeevent)(bright_event);
  793.          (*functions->freeevent)(vibrato_event);
  794.          (*functions->freeevent)(expression_event);
  795.          (*functions->freeevent)(attack_event);
  796.          (*functions->freeevent)(release_event);
  797.          (*functions->freeevent)(bank_event);
  798.          }
  799.         }
  800.         else
  801.         {
  802.         (*functions->freeevent)(volume_event);
  803.         (*functions->freeevent)(panpot_event);
  804.         (*functions->freeevent)(reverb_event);
  805.         (*functions->freeevent)(chorus_event);
  806.         (*functions->freeevent)(variation_event);
  807.         (*functions->freeevent)(harmonic_event);
  808.         (*functions->freeevent)(bright_event);
  809.         (*functions->freeevent)(vibrato_event);
  810.         (*functions->freeevent)(expression_event);
  811.         (*functions->freeevent)(attack_event);
  812.         (*functions->freeevent)(release_event);
  813.         }
  814.        }
  815.        else
  816.        {
  817.        (*functions->freeevent)(volume_event);
  818.        (*functions->freeevent)(panpot_event);
  819.        (*functions->freeevent)(reverb_event);
  820.        (*functions->freeevent)(chorus_event);
  821.        (*functions->freeevent)(variation_event);
  822.        (*functions->freeevent)(harmonic_event);
  823.        (*functions->freeevent)(bright_event);
  824.        (*functions->freeevent)(vibrato_event);
  825.        (*functions->freeevent)(expression_event);
  826.        (*functions->freeevent)(attack_event);
  827.        }
  828.       }
  829.       else
  830.       {
  831.       (*functions->freeevent)(volume_event);
  832.       (*functions->freeevent)(panpot_event);
  833.       (*functions->freeevent)(reverb_event);
  834.       (*functions->freeevent)(chorus_event);
  835.       (*functions->freeevent)(variation_event);
  836.       (*functions->freeevent)(harmonic_event);
  837.       (*functions->freeevent)(bright_event);
  838.       (*functions->freeevent)(vibrato_event);
  839.       (*functions->freeevent)(expression_event);
  840.       }
  841.      }
  842.      else
  843.      {
  844.      (*functions->freeevent)(volume_event);
  845.      (*functions->freeevent)(panpot_event);
  846.      (*functions->freeevent)(reverb_event);
  847.      (*functions->freeevent)(chorus_event);
  848.      (*functions->freeevent)(variation_event);
  849.      (*functions->freeevent)(harmonic_event);
  850.      (*functions->freeevent)(bright_event);
  851.      (*functions->freeevent)(vibrato_event);
  852.      }
  853.     }
  854.     else
  855.     {
  856.       (*functions->freeevent)(volume_event);
  857.       (*functions->freeevent)(panpot_event);
  858.       (*functions->freeevent)(reverb_event);
  859.       (*functions->freeevent)(chorus_event);
  860.       (*functions->freeevent)(variation_event);
  861.       (*functions->freeevent)(harmonic_event);
  862.       (*functions->freeevent)(bright_event);
  863.     }
  864.        }
  865.        else
  866.        {
  867.       (*functions->freeevent)(volume_event);
  868.       (*functions->freeevent)(panpot_event);
  869.       (*functions->freeevent)(reverb_event);
  870.       (*functions->freeevent)(chorus_event);
  871.       (*functions->freeevent)(variation_event);
  872.       (*functions->freeevent)(harmonic_event);
  873.        }
  874.       }
  875.       else
  876.       {
  877.     (*functions->freeevent)(volume_event);
  878.     (*functions->freeevent)(panpot_event);
  879.     (*functions->freeevent)(reverb_event);
  880.     (*functions->freeevent)(chorus_event);
  881.     (*functions->freeevent)(variation_event);
  882.       }
  883.      }
  884.      else
  885.      {
  886.        (*functions->freeevent)(volume_event);
  887.        (*functions->freeevent)(panpot_event);
  888.        (*functions->freeevent)(reverb_event);
  889.        (*functions->freeevent)(chorus_event);
  890.      }
  891.     }
  892.     else
  893.     {
  894.     (*functions->freeevent)(volume_event);
  895.     (*functions->freeevent)(panpot_event);
  896.     (*functions->freeevent)(reverb_event);
  897.     }
  898.    }
  899.    else
  900.    {
  901.    (*functions->freeevent)(volume_event);
  902.    (*functions->freeevent)(panpot_event);
  903.    }
  904.   }
  905.   else
  906.   {
  907.   (*functions->freeevent)(volume_event);
  908.   }
  909.  }
  910. }
  911. //writes sysex into track
  912.  
  913. static void __saveds insertsysex(char *buff, short size, struct MNXGTool *tool,  const LONG time)
  914. {
  915.     struct StringEvent *event;
  916.     struct String *string;
  917.  
  918.     event = (struct StringEvent *) (*functions->allocevent)();
  919.      if (event)
  920.       {
  921.     string = (struct String *) (*functions->myalloc)(size + 3, MEMF_CLEAR);
  922.     if (string)
  923.     {
  924.         event->next = NULL;
  925.         event->string = string;
  926.         memcpy(string->string,  buff,  size);
  927.         string->length = size + 2;
  928.         event->type = EVENT_SYSX;
  929.         event->status = MIDI_SYSX;
  930.         event->time = time;
  931.         event->tool = tool->tool.next;
  932.         if (lock_clip(&(tool->tool.track->clip)))
  933.           {
  934.         event->next = (struct StringEvent *)tool->tool.track->clip.events.first;
  935.         tool->tool.track->clip.events.first = (struct Event *)(*functions->sorteventlist)(event);
  936.         unlock_clip(&(tool->tool.track->clip));
  937.           }
  938.         else
  939.           {
  940.         (*functions->freelist)(event);
  941.           }
  942.  
  943.     }
  944.       }
  945.  
  946. }
  947.  
  948. // the routine for sending SysEx-data thru the pipeline
  949.  
  950. static void __saveds sendsysex(char *buff,  short size,  struct MNXGTool *tool,  const LONG time)
  951. {
  952.     struct StringEvent *event;
  953.     struct String *string;
  954.  
  955.     event = (struct StringEvent *) (*functions->allocevent)();
  956.      if (event)
  957.       {
  958.     string = (struct String *) (*functions->myalloc)(size + 3, MEMF_CLEAR);
  959.     if (string)
  960.     {
  961.         event->string = string;
  962.         memcpy(string->string,  buff,  size);
  963.         string->length = size + 2;
  964.         event->type = EVENT_SYSX;
  965.         event->status = MIDI_SYSX;
  966.         event->time = time;
  967.         event->tool = tool->tool.next;
  968.         WaitTOF();
  969.         (*functions->qevent)(event);
  970.         (*functions->myfree)(string);
  971.     }
  972.       }
  973.  
  974. }
  975.  
  976. static void __saveds trans_hx(struct MNXGTool *tool,  const LONG time,  char *sysx, int sw)
  977. {
  978.   LONG size;
  979.   int a,  b,  x,  y ;
  980.   UBYTE abuf[32];
  981.   char chr[4];
  982.   char *zbuf = NULL;
  983.   struct Event *sysx_event;
  984.  
  985.     //translate sysexbuffer into hex
  986.  
  987.   size = strlen(sysx);
  988.   zbuf = (char *)AllocVec(size+2,  MEMF_ANY|MEMF_CLEAR);
  989.   if(zbuf)
  990.      {
  991.        CopyMem(sysx,  zbuf,  size);
  992.        b=0;
  993.        for(a=0;a < size;a=a+2)
  994.        {
  995.          chr[0] = zbuf[a];
  996.          chr[1] = zbuf[a+1];
  997.  
  998.          x=(isdigit((int)chr[0]))? (chr[0]&0xF) : ((chr[0]&0xDF)-55); //this is the
  999.          y=(isdigit((int)chr[1]))? (chr[1]&0xF) : ((chr[1]&0xDF)-55); //the translate-core
  1000.  
  1001.          abuf[b++] = ((x<<4)|y);   //writing with bitmanipulation
  1002.         }
  1003.       //send hexdata
  1004.  
  1005.        FreeVec(zbuf);
  1006.        if (sw == 0) sendsysex(abuf,  b,  tool,  time);
  1007.        if (sw == 1) insertsysex(abuf,  b,  tool,  time);
  1008.  
  1009.      }
  1010.  
  1011. }
  1012.  
  1013.  
  1014.  
  1015. // Writes all values of the sliders and more  in the main window
  1016.  
  1017. long __saveds display_routine(struct Window *window,      /* Window where the gadget lives. */
  1018.                   struct Gadget *gadget,      /* The gadget itself. */
  1019.                   unsigned long value)       /* The value to display. */
  1020. {
  1021.   char text[10];
  1022.   char tname[32];
  1023.  
  1024.  
  1025.   char P01text[4];
  1026.   char varfx01text[4];
  1027.   const short id = gadget->GadgetID;
  1028.   struct RastPort *rp = window->RPort;
  1029.   char name[15];
  1030.   int i=0;
  1031.   UBYTE bnk[]=
  1032.   {0, 1, 3, 6, 8, 12, 14, 16, 17, 18, 19, 20, 24, 25, 27, 28, 32, 33, 34, 35, 36, 37, 38, 40,
  1033.   41, 42, 43, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 96, 97, 98, 99, 100, 101};
  1034.  
  1035.   UBYTE bnkval[]=
  1036.   {0, 1, 3, 6, 8, 12, 14, 16, 17, 18, 19, 20, 24, 25, 27, 28, 32, 33, 34, 35, 36, 37, 38, 40,
  1037.   41, 42, 43, 45, 64, 65, 66, 67, 68, 69, 70, 71, 72, 96, 97, 98, 99, 100, 101};
  1038.  
  1039.  
  1040.   SetAPen(rp,  1);
  1041.   SetBPen(rp,  0);
  1042.   SetDrMd(rp,  JAM2);
  1043.  
  1044.      switch (id)
  1045.           {
  1046.           case VOLUME_GADGET:
  1047.         Move(rp,  297,  23);
  1048.         sprintf(text,  "%3ld",  value);
  1049.         Text(rp,  text,  3);
  1050.         break;
  1051.           case PANPOT_GADGET:
  1052.         Move(rp,  297,  35);
  1053.         sprintf(text,  "%3ld",  value);
  1054.         Text(rp,  text,  3);
  1055.         break;
  1056.           case REVERB_GADGET:
  1057.         Move(rp,  297,  47);
  1058.         sprintf(text,  "%3ld",  value);
  1059.         Text(rp,  text,  3);
  1060.         break;
  1061.           case CHORUS_GADGET:
  1062.         Move(rp,  297,  59);
  1063.         sprintf(text,  "%3ld",  value);
  1064.         Text(rp,  text,  3);
  1065.         break;
  1066.           case VARIATION_GADGET:
  1067.         Move(rp,  297,  71);
  1068.         sprintf(text,  "%3ld",  value);
  1069.         Text(rp,  text,  3);
  1070.         break;
  1071.           case HARMONIC_GADGET:
  1072.         Move(rp,  297,  83);
  1073.         sprintf(text,  "%3ld",  value);
  1074.         Text(rp,  text,  3);
  1075.         break;
  1076.           case BRIGHT_GADGET:
  1077.         Move(rp,  297,  95);
  1078.         sprintf(text,  "%3ld",  value);
  1079.         Text(rp,  text,  3);
  1080.         break;
  1081.           case VIBRATO_GADGET:
  1082.         Move(rp,  297,  107);
  1083.         sprintf(text,  "%3ld",  value);
  1084.         Text(rp,  text,  3);
  1085.         break;
  1086.           case EXPRESSION_GADGET:
  1087.         Move(rp,  297,  119);
  1088.         sprintf(text,  "%3ld",  value);
  1089.         Text(rp,  text,  3);
  1090.         break;
  1091.           case ATTACK_GADGET:
  1092.         Move(rp,  297,  131);
  1093.         sprintf(text,  "%3ld",  value);
  1094.         Text(rp,  text,  3);
  1095.         break;
  1096.           case RELEASE_GADGET:
  1097.         Move(rp,  297,  143);
  1098.         sprintf(text,  "%3ld",  value);
  1099.         Text(rp,  text,  3);
  1100.         break;
  1101.           case BANK_GADGET:
  1102.         banknr = bnk[value];
  1103.         sprintf(text,  "%3ld",  banknr);
  1104.         Move(rp,  297,  170);
  1105.         Text(rp,  text,  3);
  1106.         break;
  1107.           case PC_GADGET:
  1108.         prgrm = value;
  1109.         Move(rp,  297,  182);
  1110.         if (p == 0) sprintf(text,  "%3ld",  prgrm);
  1111.         else if (p ==1) sprintf(text,  "%3ld",  prgrm+1);
  1112.         Text(rp,  text,  3);
  1113.         break;
  1114.           default:
  1115.         break;
  1116.           }
  1117. sprintf(P01text,  "%1ld",  p);
  1118. Move(rp,  9,  182);
  1119. Text(rp,  P01text,  1);
  1120.  
  1121. sprintf(tname,  "Name:%15.15s",  (matrix[banknr * MAX_PROGRAMS+prgrm])?(char *)matrix[banknr * MAX_PROGRAMS+prgrm]:(char *)EMPTY);
  1122. SetAPen(rp,  4);
  1123. SetBPen(rp,  7);
  1124. SetDrMd(rp,  INVERSVID|JAM2);
  1125. Move(rp,  88,  157);
  1126. Text(rp,  tname,  strlen(tname));
  1127.  
  1128.  
  1129. return (value);
  1130. }
  1131.  
  1132. //Drag & draw functions for the gadgets
  1133.  
  1134. static long drag_embossed_prop(struct Window *window,  short id,  UBYTE min)
  1135. {
  1136.   long value = (*functions->DragEmbossedProp)(window,  id);
  1137.   if (value < min)
  1138.     {
  1139.       value = min;
  1140.       (*functions->ModifyEmbossedProp)(window,  id,  value,  0,  0,  0,  0,  0);
  1141.     }
  1142.   (*functions->DrawEmbossedProp)(window,  id);
  1143.  
  1144.   return value;
  1145. }
  1146.  
  1147. static long shift_embossed_prop(struct Window *window,  short id,  short shift,  UBYTE min)
  1148. {
  1149.   long value = (*functions->ShiftEmbossedProp)(window,  id,  shift,  0);
  1150.   if (value < min)
  1151.     {
  1152.       value = min;
  1153.       (*functions->ModifyEmbossedProp)(window,  id,  value,  0,  0,  0,  0,  0);
  1154.     }
  1155.   (*functions->DrawEmbossedProp)(window,  id);
  1156.  
  1157.   return value;
  1158. }
  1159.  
  1160.  
  1161. //handels writing the values to track
  1162.  
  1163. static void insert_pc(struct MNXGTool *tool)
  1164. {
  1165.  if (!functions->running)
  1166.  {
  1167.   const long time = functions->starttime;
  1168.   struct Event *volume_event = (struct Event *)(*functions->allocevent)();
  1169.   if (volume_event)
  1170.   {
  1171.    struct Event *panpot_event = (struct Event *)(*functions->allocevent)();
  1172.    if (panpot_event)
  1173.    {
  1174.     struct Event *reverb_event = (struct Event *)(*functions->allocevent)();
  1175.     if (reverb_event)
  1176.     {
  1177.      struct Event *chorus_event = (struct Event *)(*functions->allocevent)();
  1178.      if (chorus_event)
  1179.      {
  1180.       struct Event *variation_event = (struct Event *)(*functions->allocevent)();
  1181.       if (variation_event)
  1182.       {
  1183.        struct Event *harmonic_event = (struct Event *)(*functions->allocevent)();
  1184.        if (harmonic_event)
  1185.        {
  1186.     struct Event *bright_event = (struct Event *)(*functions->allocevent)();
  1187.     if (bright_event)
  1188.     {
  1189.      struct Event *vibrato_event = (struct Event *)(*functions->allocevent)();
  1190.      if (vibrato_event)
  1191.      {
  1192.       struct Event *expression_event = (struct Event *)(*functions->allocevent)();
  1193.       if (expression_event)
  1194.       {
  1195.        struct Event *attack_event = (struct Event *)(*functions->allocevent)();
  1196.        if (attack_event)
  1197.        {
  1198.         struct Event *release_event = (struct Event *)(*functions->allocevent)();
  1199.         if (release_event)
  1200.         {
  1201.          struct Event *bank_event = (struct Event *)(*functions->allocevent)();
  1202.          if (bank_event)
  1203.          {
  1204.           struct Event *pc_event = (struct Event *)(*functions->allocevent)();
  1205.           if (pc_event)
  1206.           {
  1207.            volume_event->type     =
  1208.            panpot_event->type     =
  1209.            reverb_event->type     =
  1210.            chorus_event->type     =
  1211.            variation_event->type  =
  1212.            harmonic_event->type   =
  1213.            bright_event->type     =
  1214.            vibrato_event->type    =
  1215.            expression_event->type =
  1216.            attack_event->type     =
  1217.            release_event->type    =
  1218.            bank_event->type       =
  1219.            pc_event->type         =  EVENT_VOICE;
  1220.  
  1221.            volume_event->status     =
  1222.            panpot_event->status     =
  1223.            reverb_event->status     =
  1224.            chorus_event->status     =
  1225.            variation_event->status  =
  1226.            harmonic_event->status   =
  1227.            bright_event->status     =
  1228.            vibrato_event->status    =
  1229.            expression_event->status =
  1230.            attack_event->status     =
  1231.            release_event->status    =
  1232.            bank_event->status       = MIDI_CCHANGE;
  1233.  
  1234.            volume_event->byte1 = CTR7;
  1235.            volume_event->byte2 = tool->volume;
  1236.  
  1237.            panpot_event->byte1 = CTR10;
  1238.            panpot_event->byte2 = tool->panpot;
  1239.  
  1240.            reverb_event->byte1 = CTR91;
  1241.            reverb_event->byte2 = tool->reverb;
  1242.  
  1243.            chorus_event->byte1 = CTR93;
  1244.            chorus_event->byte2 = tool->chorus;
  1245.  
  1246.            variation_event->byte1 = CTR94;
  1247.            variation_event->byte2 = tool->variation;
  1248.  
  1249.            harmonic_event->byte1 = CTR71;
  1250.            harmonic_event->byte2 = tool->harmonic;
  1251.  
  1252.            bright_event->byte1 = CTR74;
  1253.            bright_event->byte2 = tool->bright;
  1254.  
  1255.            vibrato_event->byte1 = CTR1;
  1256.            vibrato_event->byte2 = tool->vibrato;
  1257.  
  1258.            expression_event->byte1 = CTR11;
  1259.            expression_event->byte2 = tool->expression;
  1260.  
  1261.            attack_event->byte1 = CTR73;
  1262.            attack_event->byte2 = tool->attack;
  1263.  
  1264.            release_event->byte1 = CTR72;
  1265.            release_event->byte2 = tool->release;
  1266.  
  1267.            bank_event->byte1 = CTR32;
  1268.            bank_event->byte2 = banknr;
  1269.  
  1270.            pc_event->status = MIDI_PCHANGE;
  1271.            pc_event->byte1  = tool->pc;
  1272.  
  1273.            volume_event->time     = time;
  1274.            panpot_event->time     = time;
  1275.            reverb_event->time     = time;
  1276.            chorus_event->time     = time;
  1277.            variation_event->time  = time;
  1278.            harmonic_event->time   = time;
  1279.            bright_event->time     = time;
  1280.            vibrato_event->time    = time;
  1281.            expression_event->time = time;
  1282.            attack_event->time     = time;
  1283.            release_event->time    = time;
  1284.            bank_event->time       = time;
  1285.            pc_event->time         = time + 1;
  1286.  
  1287.  
  1288.            volume_event->tool     =
  1289.            panpot_event->tool     =
  1290.            reverb_event->tool     =
  1291.            chorus_event->tool     =
  1292.            variation_event->tool  =
  1293.            harmonic_event->tool   =
  1294.            bright_event->tool     =
  1295.            vibrato_event->tool    =
  1296.            expression_event->tool =
  1297.            attack_event->tool     =
  1298.            release_event->tool    =
  1299.            bank_event->tool       =
  1300.            pc_event->tool         = tool->tool.next;
  1301.  
  1302.            volume_event->next     = panpot_event;
  1303.            panpot_event->next     = reverb_event;
  1304.            reverb_event->next     = chorus_event;
  1305.            chorus_event->next     = variation_event;
  1306.            variation_event->next  = harmonic_event;
  1307.            harmonic_event->next   = bright_event;
  1308.            bright_event->next     = vibrato_event;
  1309.            vibrato_event->next    = expression_event;
  1310.            expression_event->next = attack_event;
  1311.            attack_event->next     = release_event;
  1312.            release_event->next    = bank_event;
  1313.            bank_event->next       = pc_event;
  1314.            pc_event->next         = NULL;
  1315.  
  1316.            if (lock_clip(&(tool->tool.track->clip)))
  1317.          {
  1318.            pc_event->next = tool->tool.track->clip.events.first;
  1319.            tool->tool.track->clip.events.first =
  1320.            (struct Event *)(*functions->sorteventlist)(volume_event);
  1321.            unlock_clip(&(tool->tool.track->clip));
  1322.          }
  1323.            else
  1324.          {
  1325.            (*functions->freelist)(volume_event);
  1326.          }
  1327.           }
  1328.           else
  1329.           {
  1330.           (*functions->freeevent)(volume_event);
  1331.           (*functions->freeevent)(panpot_event);
  1332.           (*functions->freeevent)(reverb_event);
  1333.           (*functions->freeevent)(chorus_event);
  1334.           (*functions->freeevent)(harmonic_event);
  1335.           (*functions->freeevent)(variation_event);
  1336.           (*functions->freeevent)(bright_event);
  1337.           (*functions->freeevent)(vibrato_event);
  1338.           (*functions->freeevent)(expression_event);
  1339.           (*functions->freeevent)(attack_event);
  1340.           (*functions->freeevent)(release_event);
  1341.           (*functions->freeevent)(bank_event);
  1342.           }
  1343.          }
  1344.          else
  1345.          {
  1346.          (*functions->freeevent)(volume_event);
  1347.          (*functions->freeevent)(panpot_event);
  1348.          (*functions->freeevent)(reverb_event);
  1349.          (*functions->freeevent)(chorus_event);
  1350.          (*functions->freeevent)(variation_event);
  1351.          (*functions->freeevent)(harmonic_event);
  1352.          (*functions->freeevent)(bright_event);
  1353.          (*functions->freeevent)(vibrato_event);
  1354.          (*functions->freeevent)(expression_event);
  1355.          (*functions->freeevent)(attack_event);
  1356.          (*functions->freeevent)(release_event);
  1357.          }
  1358.         }
  1359.         else
  1360.         {
  1361.         (*functions->freeevent)(volume_event);
  1362.         (*functions->freeevent)(panpot_event);
  1363.         (*functions->freeevent)(reverb_event);
  1364.         (*functions->freeevent)(chorus_event);
  1365.         (*functions->freeevent)(variation_event);
  1366.         (*functions->freeevent)(harmonic_event);
  1367.         (*functions->freeevent)(bright_event);
  1368.         (*functions->freeevent)(vibrato_event);
  1369.         (*functions->freeevent)(expression_event);
  1370.         (*functions->freeevent)(attack_event);
  1371.         }
  1372.        }
  1373.        else
  1374.        {
  1375.        (*functions->freeevent)(volume_event);
  1376.        (*functions->freeevent)(panpot_event);
  1377.        (*functions->freeevent)(reverb_event);
  1378.        (*functions->freeevent)(chorus_event);
  1379.        (*functions->freeevent)(variation_event);
  1380.        (*functions->freeevent)(harmonic_event);
  1381.        (*functions->freeevent)(bright_event);
  1382.        (*functions->freeevent)(vibrato_event);
  1383.        (*functions->freeevent)(expression_event);
  1384.        }
  1385.       }
  1386.       else
  1387.       {
  1388.       (*functions->freeevent)(volume_event);
  1389.       (*functions->freeevent)(panpot_event);
  1390.       (*functions->freeevent)(reverb_event);
  1391.       (*functions->freeevent)(chorus_event);
  1392.       (*functions->freeevent)(variation_event);
  1393.       (*functions->freeevent)(harmonic_event);
  1394.       (*functions->freeevent)(bright_event);
  1395.       (*functions->freeevent)(vibrato_event);
  1396.       }
  1397.      }
  1398.      else
  1399.      {
  1400.      (*functions->freeevent)(volume_event);
  1401.      (*functions->freeevent)(panpot_event);
  1402.      (*functions->freeevent)(reverb_event);
  1403.      (*functions->freeevent)(chorus_event);
  1404.      (*functions->freeevent)(variation_event);
  1405.      (*functions->freeevent)(harmonic_event);
  1406.      (*functions->freeevent)(bright_event);
  1407.      }
  1408.     }
  1409.     else
  1410.     {
  1411.     (*functions->freeevent)(volume_event);
  1412.     (*functions->freeevent)(panpot_event);
  1413.     (*functions->freeevent)(reverb_event);
  1414.     (*functions->freeevent)(chorus_event);
  1415.     (*functions->freeevent)(variation_event);
  1416.     (*functions->freeevent)(harmonic_event);
  1417.     }
  1418.        }
  1419.        else
  1420.        {
  1421.        (*functions->freeevent)(volume_event);
  1422.        (*functions->freeevent)(panpot_event);
  1423.        (*functions->freeevent)(reverb_event);
  1424.        (*functions->freeevent)(chorus_event);
  1425.        (*functions->freeevent)(variation_event);
  1426.        }
  1427.       }
  1428.       else
  1429.       {
  1430.       (*functions->freeevent)(volume_event);
  1431.       (*functions->freeevent)(panpot_event);
  1432.       (*functions->freeevent)(reverb_event);
  1433.       (*functions->freeevent)(chorus_event);
  1434.       }
  1435.      }
  1436.      else
  1437.      {
  1438.      (*functions->freeevent)(volume_event);
  1439.      (*functions->freeevent)(panpot_event);
  1440.      (*functions->freeevent)(reverb_event);
  1441.      }
  1442.     }
  1443.     else
  1444.     {
  1445.     (*functions->freeevent)(volume_event);
  1446.     (*functions->freeevent)(panpot_event);
  1447.     }
  1448.    }
  1449.    else
  1450.    {
  1451.    (*functions->freeevent)(volume_event);
  1452.    }
  1453.   }
  1454.  }
  1455. }
  1456.  
  1457.  
  1458.  
  1459.  
  1460. //to hear the changes
  1461.  
  1462. static void send_note(struct MNXGTool *tool,  const long time,  const UBYTE note)
  1463. {
  1464.   struct NoteEvent *on_event = (struct NoteEvent *)(*functions->allocevent)();
  1465.   if (on_event)
  1466.     {
  1467.       struct NoteEvent *off_event = (struct NoteEvent *)(*functions->allocevent)();
  1468.       if (off_event)
  1469.     {
  1470.       on_event->next  =
  1471.       off_event->next = NULL;
  1472.  
  1473.       on_event->type  =
  1474.       off_event->type = EVENT_VOICE;
  1475.  
  1476.       on_event->status  = MIDI_NOTEON;
  1477.       off_event->status = MIDI_NOTEOFF;
  1478.  
  1479.       on_event->value  =
  1480.       off_event->value = note;
  1481.  
  1482.       on_event->velocity = 80;
  1483.  
  1484.       on_event->time  = time;
  1485.       off_event->time = time + 96;
  1486.  
  1487.       on_event->tool  =
  1488.       off_event->tool = tool->tool.next;
  1489.  
  1490.       (*functions->qevent)(on_event);
  1491.       (*functions->qevent)(off_event);
  1492.     }
  1493.       else
  1494.     {
  1495.       (*functions->freeevent)(on_event);
  1496.     }
  1497.     }
  1498. }
  1499.  
  1500. static void send_pc_and_note(struct MNXGTool *tool,  const long time,  const UBYTE note)
  1501. {
  1502.   send_pc(tool,  time);
  1503.   send_note(tool,  time + 3,  note);
  1504. }
  1505.  
  1506. //the center off all
  1507.  
  1508. static void __saveds edittoolcode(struct MNXGTool *tool)
  1509. {
  1510.   struct IntuiMessage *message;
  1511.   struct Window *window;
  1512.   LONG class,  code,  time;
  1513.   struct Gadget *gadget;
  1514.   struct NewWindow *newwindow;
  1515.   int i,  revres=0;
  1516.   UBYTE bankval;
  1517.   char *revtypebt, *storagebt;
  1518.   char revtypebyte[11][4] ={
  1519.   "0100", "0101", "0202", "0201", "0202", "0300", "0301", "0400", "1000", "1100", "1300"};
  1520.  
  1521.  
  1522.   MNXGNewWindowStructure1.Screen = functions->screen;
  1523.  
  1524.   if (tool->tool.touched & TOUCH_EDIT)
  1525.     {
  1526.       MNXGNewWindowStructure1.LeftEdge = tool->tool.left;
  1527.       MNXGNewWindowStructure1.TopEdge = tool->tool.top;
  1528.       MNXGNewWindowStructure1.Width = tool->tool.width;
  1529.       MNXGNewWindowStructure1.Height = tool->tool.height;
  1530.     }
  1531.   
  1532.   if (!tool->tool.touched)
  1533.     {
  1534.       MNXG_tool_init(tool);
  1535.     }
  1536.  
  1537.   newwindow = (struct NewWindow *) (*functions->DupeNewWindow)(&MNXGNewWindowStructure1);
  1538.   if (!newwindow)
  1539.     {
  1540.       return;
  1541.     }
  1542.   newwindow->Title = 0;
  1543.   newwindow->Flags |= BORDERLESS;
  1544.   newwindow->Flags &= ~0xF;
  1545.   newwindow->BlockPen = 0;
  1546.   newwindow->DetailPen = 0;
  1547.  
  1548.   window = (struct Window *) (*functions->FlashyOpenWindow)(newwindow);
  1549.   if (!window)
  1550.     {
  1551.       return;
  1552.     }
  1553.   tool->tool.window = window;
  1554.   (*functions->EmbossWindowOn)(window, WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG,  MNXG_NAME, (short)-1, (short)-1, 0, 0);
  1555.  
  1556. // because these sliders are identical we can use a loop
  1557.   for (i = VOLUME_GADGET;
  1558.        i <= PC_GADGET;
  1559.        i += 3)
  1560.     {
  1561.       if (!(i == BANK_GADGET))
  1562.      {
  1563.      (*functions->FatEmbossedPropOn)(window,i, i + 1, i + 2,
  1564.                     (void *)display_routine,
  1565.                     128, 1);
  1566.      }
  1567.       else
  1568.      {
  1569.      (*functions->FatEmbossedPropOn)(window,
  1570.                   BANK_GADGET,
  1571.                   BANKDOWN_GADGET,
  1572.                   BANKUP_GADGET,
  1573.                   (void *)display_routine,
  1574.                   43, 1);
  1575.      }
  1576.     }
  1577.  
  1578.  
  1579.   (*functions->EmbossOn)(window,  WRITE_GADGET,  1);
  1580.   (*functions->EmbossOn)(window,  TEST_GADGET,  1);
  1581.   (*functions->EmbossOn)(window,  P01_GADGET,  1);
  1582.   (*functions->EmbossOn)(window,  DEFAULT_GADGET,  1);
  1583.   (*functions->EmbossOn)(window,  INSY_GADGET,  1);
  1584.  
  1585.  
  1586.   (*functions->ModifyEmbossedProp)(window,  VOLUME_GADGET,  tool->volume,  0,  0,  0,  0,  0);
  1587.   (*functions->ModifyEmbossedProp)(window,  PANPOT_GADGET,  tool->panpot,  0,  0,  0,  0,  0);
  1588.   (*functions->ModifyEmbossedProp)(window,  REVERB_GADGET,  tool->reverb,  0,  0,  0,  0,  0);
  1589.   (*functions->ModifyEmbossedProp)(window,  CHORUS_GADGET,  tool->chorus,  0,  0,  0,  0,  0);
  1590.   (*functions->ModifyEmbossedProp)(window,  VARIATION_GADGET,  tool->variation,  0,  0,  0,  0,  0);
  1591.   (*functions->ModifyEmbossedProp)(window,  HARMONIC_GADGET,  tool->harmonic,  0,  0,  0,  0,  0);
  1592.   (*functions->ModifyEmbossedProp)(window,  BRIGHT_GADGET,  tool->bright,  0,  0,  0,  0,  0);
  1593.   (*functions->ModifyEmbossedProp)(window,  VIBRATO_GADGET,  tool->vibrato,  0,  0,  0,  0,  0);
  1594.   (*functions->ModifyEmbossedProp)(window,  EXPRESSION_GADGET,  tool->expression,  0,  0,  0,  0,  0);
  1595.   (*functions->ModifyEmbossedProp)(window,  ATTACK_GADGET,  tool->attack,  0,  0,  0,  0,  0);
  1596.   (*functions->ModifyEmbossedProp)(window,  RELEASE_GADGET,  tool->release,  0,  0,  0,  0,  0);
  1597.   (*functions->ModifyEmbossedProp)(window,  BANK_GADGET,  tool->bank,  0,  0,  0,  0,  0);
  1598.   (*functions->ModifyEmbossedProp)(window,  PC_GADGET,  tool->pc,  0,  0,  0,  0,  0);
  1599.   
  1600.   for (i = VOLUME_GADGET;
  1601.        i <= PC_GADGET;
  1602.        i += 3)
  1603.     {
  1604.       (*functions->DrawEmbossedProp)(window,  i);
  1605.     }
  1606.  
  1607.  
  1608.   send_pc_and_note(tool,  functions->timenow,  60);
  1609.  
  1610.   for (;;)
  1611.     {
  1612.  
  1613.       (*functions->SelectEmbossed)(window,  INSY_GADGET,  ins);
  1614.  
  1615.       message = (struct IntuiMessage *) (*functions->GetIntuiMessage)(window);
  1616.       class = message->Class;
  1617.       code = message->Code;
  1618.       gadget = (struct Gadget *) message->IAddress;
  1619.       class = (*functions->SystemGadgets)(window, class, gadget, code);
  1620.  
  1621.       ReplyMsg((struct Message *)message);
  1622.  
  1623.  
  1624.       if (class == CLOSEWINDOW)
  1625.     {
  1626.       break;
  1627.     }
  1628.       else if (class == GADGETDOWN)
  1629.     {
  1630.       const short id = gadget->GadgetID;
  1631.       switch (id)
  1632.         {
  1633.         case VOLUME_GADGET:
  1634.           tool->volume = (UBYTE) drag_embossed_prop(window,  VOLUME_GADGET,  0);
  1635.           send_pc_and_note(tool,  functions->timenow,  60);
  1636.           break;
  1637.         case VOLUMEDOWN_GADGET:
  1638.           tool->volume = (UBYTE) shift_embossed_prop(window,  VOLUME_GADGET,  -1,  0);
  1639.           send_pc_and_note(tool,  functions->timenow,  60);
  1640.           break;
  1641.         case VOLUMEUP_GADGET:
  1642.           tool->volume = (UBYTE) shift_embossed_prop(window,  VOLUME_GADGET,  1,  0);
  1643.           send_pc_and_note(tool,  functions->timenow,  60);
  1644.           break;
  1645.         case PANPOT_GADGET:
  1646.           tool->panpot = (UBYTE) drag_embossed_prop(window,  PANPOT_GADGET,  0);
  1647.           send_pc_and_note(tool,  functions->timenow,  60);
  1648.           break;
  1649.         case PANPOTDOWN_GADGET:
  1650.           tool->panpot = (UBYTE)shift_embossed_prop(window,  PANPOT_GADGET,  -1,  0);
  1651.           send_pc_and_note(tool,  functions->timenow,  60);
  1652.           break;
  1653.         case PANPOTUP_GADGET:
  1654.           tool->panpot = (UBYTE) shift_embossed_prop(window,  PANPOT_GADGET,  1,  0);
  1655.           send_pc_and_note(tool,  functions->timenow,  60);
  1656.           break;
  1657.         case REVERB_GADGET:
  1658.           tool->reverb = (UBYTE) drag_embossed_prop(window,  REVERB_GADGET,  0);
  1659.           send_pc_and_note(tool,  functions->timenow,  60);
  1660.           break;
  1661.         case REVERBDOWN_GADGET:
  1662.           tool->reverb = (UBYTE) shift_embossed_prop(window,  REVERB_GADGET,  -1,  0);
  1663.           send_pc_and_note(tool,  functions->timenow,  60);
  1664.           break;
  1665.         case REVERBUP_GADGET:
  1666.           tool->reverb = (UBYTE) shift_embossed_prop(window,  REVERB_GADGET,  1,  0);
  1667.           send_pc_and_note(tool,  functions->timenow,  60);
  1668.           break;
  1669.         case CHORUS_GADGET:
  1670.           tool->chorus = (UBYTE) drag_embossed_prop(window,  CHORUS_GADGET,  0);
  1671.           send_pc_and_note(tool,  functions->timenow,  60);
  1672.           break;
  1673.         case CHORUSDOWN_GADGET:
  1674.           tool->chorus = (UBYTE) shift_embossed_prop(window,  CHORUS_GADGET,  -1,  0);
  1675.           send_pc_and_note(tool,  functions->timenow,  60);
  1676.           break;
  1677.         case CHORUSUP_GADGET:
  1678.           tool->chorus = (UBYTE) shift_embossed_prop(window,  CHORUS_GADGET,  1,  0);
  1679.           send_pc_and_note(tool,  functions->timenow,  60);
  1680.           break;
  1681.         case VARIATION_GADGET:
  1682.           tool->variation = (UBYTE) drag_embossed_prop(window,  VARIATION_GADGET,  0);
  1683.           send_pc_and_note(tool,  functions->timenow,  60);
  1684.           break;
  1685.         case VARIATIONDOWN_GADGET:
  1686.           tool->variation = (UBYTE) shift_embossed_prop(window,  VARIATION_GADGET,  -1,  0);
  1687.           send_pc_and_note(tool,  functions->timenow,  60);
  1688.           break;
  1689.         case VARIATIONUP_GADGET:
  1690.           tool->variation = (UBYTE) shift_embossed_prop(window,  VARIATION_GADGET,  1,  0);
  1691.           send_pc_and_note(tool,  functions->timenow,  60);
  1692.           break;
  1693.         case HARMONIC_GADGET:
  1694.           tool->harmonic = (UBYTE) drag_embossed_prop(window,  HARMONIC_GADGET,  0);
  1695.           send_pc_and_note(tool,  functions->timenow,  60);
  1696.           break;
  1697.         case HARMONICDOWN_GADGET:
  1698.           tool->harmonic = (UBYTE) shift_embossed_prop(window,  HARMONIC_GADGET,  -1,  0);
  1699.           send_pc_and_note(tool,  functions->timenow,  60);
  1700.           break;
  1701.         case HARMONICUP_GADGET:
  1702.           tool->harmonic = (UBYTE) shift_embossed_prop(window,  HARMONIC_GADGET,  1,  0);
  1703.           send_pc_and_note(tool,  functions->timenow,  60);
  1704.           break;
  1705.         case BRIGHT_GADGET:
  1706.           tool->bright = (UBYTE) drag_embossed_prop(window,  BRIGHT_GADGET,  0);
  1707.           send_pc_and_note(tool,  functions->timenow,  60);
  1708.           break;
  1709.         case BRIGHTDOWN_GADGET:
  1710.           tool->bright = (UBYTE) shift_embossed_prop(window,  BRIGHT_GADGET,  -1,  0);
  1711.           send_pc_and_note(tool,  functions->timenow,  60);
  1712.           break;
  1713.         case BRIGHTUP_GADGET:
  1714.           tool->bright = (UBYTE) shift_embossed_prop(window,  BRIGHT_GADGET,  1,  0);
  1715.           send_pc_and_note(tool,  functions->timenow,  60);
  1716.           break;
  1717.         case VIBRATO_GADGET:
  1718.           tool->vibrato = (UBYTE) drag_embossed_prop(window,  VIBRATO_GADGET,  0);
  1719.           send_pc_and_note(tool,  functions->timenow,  60);
  1720.           break;
  1721.         case VIBRATODOWN_GADGET:
  1722.           tool->vibrato = (UBYTE) shift_embossed_prop(window,  VIBRATO_GADGET,  -1,  0);
  1723.           send_pc_and_note(tool,  functions->timenow,  60);
  1724.           break;
  1725.         case VIBRATOUP_GADGET:
  1726.           tool->vibrato = (UBYTE) shift_embossed_prop(window,  VIBRATO_GADGET,  1,  0);
  1727.           send_pc_and_note(tool,  functions->timenow,  60);
  1728.           break;
  1729.         case EXPRESSION_GADGET:
  1730.           tool->expression = (UBYTE) drag_embossed_prop(window,  EXPRESSION_GADGET,  0);
  1731.           send_pc_and_note(tool,  functions->timenow,  60);
  1732.           break;
  1733.         case EXPRESSIONDOWN_GADGET:
  1734.           tool->expression = (UBYTE) shift_embossed_prop(window,  EXPRESSION_GADGET,  -1,  0);
  1735.           send_pc_and_note(tool,  functions->timenow,  60);
  1736.           break;
  1737.         case EXPRESSIONUP_GADGET:
  1738.           tool->expression = (UBYTE) shift_embossed_prop(window,  EXPRESSION_GADGET,  1,  0);
  1739.           send_pc_and_note(tool,  functions->timenow,  60);
  1740.           break;
  1741.         case ATTACK_GADGET:
  1742.           tool->attack = (UBYTE) drag_embossed_prop(window,  ATTACK_GADGET,  0);
  1743.           send_pc_and_note(tool,  functions->timenow,  60);
  1744.           break;
  1745.         case ATTACKDOWN_GADGET:
  1746.           tool->attack = (UBYTE) shift_embossed_prop(window,  ATTACK_GADGET,  -1,  0);
  1747.           send_pc_and_note(tool,  functions->timenow,  60);
  1748.           break;
  1749.         case ATTACKUP_GADGET:
  1750.           tool->attack = (UBYTE) shift_embossed_prop(window,  ATTACK_GADGET,  1,  0);
  1751.           send_pc_and_note(tool,  functions->timenow,  60);
  1752.           break;
  1753.         case RELEASE_GADGET:
  1754.           tool->release = (UBYTE) drag_embossed_prop(window,  RELEASE_GADGET,  0);
  1755.           send_pc_and_note(tool,  functions->timenow,  60);
  1756.           break;
  1757.         case RELEASEDOWN_GADGET:
  1758.           tool->release = (UBYTE) shift_embossed_prop(window,  RELEASE_GADGET,  -1,  0);
  1759.           send_pc_and_note(tool,  functions->timenow,  60);
  1760.           break;
  1761.         case RELEASEUP_GADGET:
  1762.           tool->release = (UBYTE) shift_embossed_prop(window,  RELEASE_GADGET,  1,  0);
  1763.           send_pc_and_note(tool,  functions->timenow,  60);
  1764.           break;
  1765.         case BANK_GADGET:
  1766.           tool->bank = (UBYTE) drag_embossed_prop(window,  BANK_GADGET,  0);
  1767.           send_pc_and_note(tool,  functions->timenow,  60);
  1768.           break;
  1769.         case BANKDOWN_GADGET:
  1770.           tool->bank = (UBYTE)shift_embossed_prop(window,  BANK_GADGET,  -1,  0);
  1771.           send_pc_and_note(tool,  functions->timenow,  60);
  1772.           break;
  1773.         case BANKUP_GADGET:
  1774.           tool->bank = (UBYTE) shift_embossed_prop(window,  BANK_GADGET,  1,  0);
  1775.           send_pc_and_note(tool,  functions->timenow,  60);
  1776.           break;
  1777.         case PC_GADGET:
  1778.           tool->pc = (UBYTE) drag_embossed_prop(window,  PC_GADGET,  0);
  1779.           send_pc_and_note(tool,  functions->timenow,  60);
  1780.           break;
  1781.         case PCDOWN_GADGET:
  1782.           tool->pc = (UBYTE) shift_embossed_prop(window,  PC_GADGET,  -1,  0);
  1783.           send_pc_and_note(tool,  functions->timenow,  60);
  1784.           break;
  1785.         case PCUP_GADGET:
  1786.           tool->pc = (UBYTE) shift_embossed_prop(window,  PC_GADGET,  1,  0);
  1787.           send_pc_and_note(tool,  functions->timenow,  60);
  1788.           break;
  1789.         case WRITE_GADGET:
  1790.           if ((*functions->areyousure)("write to track ? Play-pointer on right place ?"))
  1791.           {
  1792.           if (!functions->running)
  1793.               {
  1794.                if (tool->insysysex != NULL) trans_hx(tool,  576,  tool->insysysex, 1);
  1795.                if (tool->resetsysex != NULL) trans_hx(tool,  1,  tool->resetsysex, 1);
  1796.                if (tool->xgonsysex != NULL) trans_hx(tool,  384,  tool->xgonsysex, 1);
  1797.                insert_pc(tool);
  1798.               }
  1799.           }
  1800.           break;
  1801.         case TEST_GADGET:
  1802.           {
  1803.         long time = functions->timenow;
  1804.         send_pc(tool,  time);
  1805.         time += 3;
  1806.         for (i = 24; i <= 84; i += 4,  time += 96)
  1807.           {
  1808.             send_note(tool,  time,  i);
  1809.           }
  1810.           }
  1811.           break;
  1812.         case P01_GADGET:
  1813.           if (p == 0)
  1814.           {
  1815.           p = 1;
  1816.           tool->pc = (UBYTE) shift_embossed_prop(window,  PC_GADGET,  0,  0);
  1817.           send_pc_and_note(tool,  functions->timenow,  60);
  1818.           break;
  1819.           }
  1820.           else
  1821.           if (p == 1)
  1822.           {
  1823.           p = 0;
  1824.           tool->pc = (UBYTE) shift_embossed_prop(window,  PC_GADGET,  0,  0);
  1825.           send_pc_and_note(tool,  functions->timenow,  60);
  1826.           break;
  1827.           }
  1828.         case DEFAULT_GADGET:
  1829.           {
  1830.           tool->volume     = 100;
  1831.           tool->panpot     = 64;
  1832.           tool->reverb     = 40;
  1833.           tool->chorus     = 0;
  1834.           tool->variation  = 40;
  1835.           tool->harmonic   = 64;
  1836.           tool->bright     = 64;
  1837.           tool->vibrato    = 0;
  1838.           tool->expression = 127;
  1839.           tool->attack     = 64;
  1840.           tool->release    = 64;
  1841.  
  1842.           (*functions->ModifyEmbossedProp)(window,  VOLUME_GADGET,  tool->volume,  0,  0,  0,  0,  0);
  1843.           (*functions->ModifyEmbossedProp)(window,  PANPOT_GADGET,  tool->panpot,  0,  0,  0,  0,  0);
  1844.           (*functions->ModifyEmbossedProp)(window,  REVERB_GADGET,  tool->reverb,  0,  0,  0,  0,  0);
  1845.           (*functions->ModifyEmbossedProp)(window,  CHORUS_GADGET,  tool->chorus,  0,  0,  0,  0,  0);
  1846.           (*functions->ModifyEmbossedProp)(window,  VARIATION_GADGET,  tool->variation,  0,  0,  0,  0,  0);
  1847.           (*functions->ModifyEmbossedProp)(window,  HARMONIC_GADGET,  tool->harmonic,  0,  0,  0,  0,  0);
  1848.           (*functions->ModifyEmbossedProp)(window,  BRIGHT_GADGET,  tool->bright,  0,  0,  0,  0,  0);
  1849.           (*functions->ModifyEmbossedProp)(window,  VIBRATO_GADGET,  tool->vibrato,  0,  0,  0,  0,  0);
  1850.           (*functions->ModifyEmbossedProp)(window,  EXPRESSION_GADGET,  tool->expression,  0,  0,  0,  0,  0);
  1851.           (*functions->ModifyEmbossedProp)(window,  ATTACK_GADGET,  tool->attack,  0,  0,  0,  0,  0);
  1852.           (*functions->ModifyEmbossedProp)(window,  RELEASE_GADGET,  tool->release,  0,  0,  0,  0,  0);
  1853.  
  1854.           for (i = VOLUME_GADGET;
  1855.            i <= RELEASE_GADGET;
  1856.            i += 3)
  1857.         {
  1858.           (*functions->DrawEmbossedProp)(window,  i);
  1859.         }
  1860.  
  1861.           send_pc_and_note(tool,  functions->timenow+30,  60);
  1862.           break;
  1863.           }
  1864.         case INSY_GADGET:
  1865.           {
  1866.           if (ins == 0)
  1867.         {
  1868.           ins = 1;
  1869.           insy[0] = 0x53;  // "S" = SYSTEM
  1870.           time = functions->timenow;
  1871.           tool->insysysex = "F043104C02015A01F7";
  1872.           trans_hx(tool,  time,  tool->insysysex, 0);
  1873.           send_pc_and_note(tool,  functions->timenow+30,  60);
  1874.           break;
  1875.         }
  1876.           else if (ins == 1)
  1877.         {
  1878.           ins = 0;
  1879.           insy[0] = 0x49;  //"I"  = INSERTION
  1880.           time = functions->timenow;
  1881.           tool->insysysex = "F043104C02015A00F7";
  1882.           trans_hx(tool,  time,  tool->insysysex, 0);
  1883.           send_pc_and_note(tool,  functions->timenow+30,  60);
  1884.           break;
  1885.         }
  1886.           }
  1887.         }
  1888.     }
  1889.       else if (class == GADGETUP)
  1890.     {
  1891.       /* Nothing. */
  1892.     }
  1893.     }
  1894.   tool->tool.window = 0;
  1895.   tool->tool.left = window->LeftEdge;
  1896.   tool->tool.top = window->TopEdge;
  1897.   tool->tool.width = window->Width;
  1898.   tool->tool.height = window->Height;
  1899.   tool->tool.touched = TOUCH_INIT | TOUCH_EDIT;
  1900.  
  1901.   for (i = VOLUME_GADGET;
  1902.        i <= PC_GADGET;
  1903.        i += 3)
  1904.     {
  1905.       (*functions->FatEmbossedPropOff)(window, i,  i + 1,  i + 2);
  1906.     }
  1907.  
  1908.   (*functions->EmbossOff)(window,  WRITE_GADGET);
  1909.   (*functions->EmbossOff)(window,  TEST_GADGET);
  1910.   (*functions->EmbossOff)(window,  P01_GADGET);
  1911.   (*functions->EmbossOff)(window,  DEFAULT_GADGET);
  1912.   (*functions->EmbossOff)(window,  INSY_GADGET);
  1913.   
  1914.   (*functions->EmbossWindowOff)(window);
  1915.   (*functions->FlashyCloseWindow)(window);
  1916.   (*functions->DeleteNewWindow)(newwindow);
  1917. }
  1918.  
  1919. //to leave the tool correct
  1920.  
  1921. void __saveds removetool()
  1922. {
  1923. FreeVec(matrix);
  1924. FreeVec(MNXG);
  1925. }
  1926.  
  1927. //start of the tool
  1928.  
  1929. struct ToolMaster * inittoolmaster()
  1930. {
  1931.   int i = 0,  bank = 0;
  1932.  
  1933.   if (!(MNXG=(UWORD *)AllocVec(sizeof (MNXGdata), MEMF_CHIP|MEMF_CLEAR))) return(NULL);
  1934.   CopyMem(&MNXGdata, MNXG,  sizeof (MNXGdata));
  1935.  
  1936.   if(!(matrix = (STRPTR *)AllocVec(MAX_BANKS*MAX_PROGRAMS*sizeof(STRPTR), MEMF_ANY|MEMF_CLEAR)))
  1937.   return(NULL);
  1938.  
  1939.    while (v[i].bank != BE)
  1940.    {
  1941.  
  1942.        bank = v[i].bank;
  1943.        matrix[bank * MAX_PROGRAMS + v[i].program] = (STRPTR)v[i].name;
  1944.        i++;
  1945.    }
  1946.  
  1947.   MNXG_image.ImageData = MNXG;
  1948.   memset((char *)&master, 0, sizeof(struct ToolMaster));
  1949.   master.toolid = MNXG_ID;
  1950.   master.image = &MNXG_image;
  1951.   strcpy(master.name,  MNXG_NAME);
  1952.   master.edittool = edittoolcode;
  1953.   master.processevent = processeventcode;
  1954.   master.tooltype = MNXG_TYPE;
  1955.   master.toolsize = sizeof(struct MNXGTool);
  1956.   master.removetool = removetool;
  1957.   return(&master);
  1958. }
  1959.